<template>
  <!-- 金币明细 -->
  <div class="goldAccount">
    <div class="top">
      <img src="@/assets/img/icons/black/back.svg" class="back" @click="$router.back()" />
      <div class="title">金币明细</div>
      <div class="placeorder"></div>
    </div>
    <div class="line"></div>
    <k-scroll
      class="scroll"
      topColor="var(--main-background-color)"
      bottomColor="var(--main-background-color)"
      topType="stretch"
      bottomType="stretch"
    >
      <div class="content">
        <div class="item" v-for="item in goldAccount" :key="JSON.stringify(item)">
          <div class="box">
            <div class="note">{{ item.note }}</div>
            <!-- <div v-if="item.gold>0" class="income">+{{item.gold}}</div>
            <div v-if="item.gold<0" class="pay">{{item.gold}}</div> -->
          </div>
          <div class="date">{{ item.time | format }}</div>
          <div v-if="item.gold > 0" class="income">+{{ item.gold }}</div>
          <div v-if="item.gold < 0" class="pay">{{ item.gold }}</div>
        </div>
      </div>
    </k-scroll>
  </div>
</template>

<script>
export default {
  name: 'goldAccount',
  mounted() {
    this.getAccount() //获取账单数据
  },
  data() {
    return {
      //金币明细数据列表
      goldAccount: [],
    }
  },
  filters: {
    //时间戳格式化日期格式
    format(t) {
      let mon = new Date(t).getMonth() + 1 //月
      let day = new Date(t).getDate() //日
      let h = new Date(t).getHours() //小时
      h = h > 9 ? h : '0' + h
      let min = new Date(t).getMinutes() //分钟
      min = min > 9 ? min : '0' + min
      return mon + '月' + day + '日 ' + h + ':' + min
    },
  },
  methods: {
    //获取金币明细账单
    getAccount() {
      this.$network
        .main('postNull', 'getGoldAccount')
        .then((data) => {
          this.goldAccount = data //赋值
        })
        .catch((err) => {
          //请求出错
          this.$dialog({
            message: err,
          })
        })
    },
  },
}
</script>

<style scoped src="./index.less" lang="less"></style>
